Problem Challenge 2

Comparing Strings containing Backspaces (medium) #

Given two strings containing backspaces (identified by the character ‘#’), check if the two strings are equal.

Example 1:

Input: str1="xy#z", str2="xzz#"
Output: true
Explanation: After applying backspaces the strings become "xz" and "xz" respectively.

Example 2:

Input: str1="xy#z", str2="xyz#"
Output: false
Explanation: After applying backspaces the strings become "xz" and "xy" respectively.

Example 3:

Input: str1="xp#", str2="xyz##"
Output: true
Explanation: After applying backspaces the strings become "x" and "x" respectively.
In "xyz##", the first '#' removes the character 'z' and the second '#' removes the character 'y'.

Example 4:

Input: str1="xywrrmp", str2="xywrrmu#p"
Output: true
Explanation: After applying backspaces the strings become "xywrrmp" and "xywrrmp" respectively.

Try it yourself #

Try solving this question here:

1 of 4 Tests Passed
ResultInputExpected OutputActual OutputReason
compare(xy#z, xzz#)truefalseIncorrect Output
compare(xp#, xyz##)truefalseIncorrect Output
compare(xywrrmp, xywrrmu#p)truefalseIncorrect Output
compare(xy#z, xyz#)falsefalseSucceeded
3.644s
Mark as Completed
←    Back
Solution Review: Problem Challenge 1
Next    →
Solution Review: Problem Challenge 2